package com.changyue.activity.me;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.changyue.bleHelper.BLEDeviceConfig;
import com.changyue.temp.databinding.ActivitySettingTempBinding;
import com.changyue.ui.HeadView;

import org.greenrobot.eventbus.EventBus;

public class SettingTempActivity extends AppCompatActivity {

    private ActivitySettingTempBinding binding;

    public static void start(Context context) {
        Intent intent = new Intent(context, SettingTempActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivitySettingTempBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        initView();
    }

    void initView() {
        binding.headView.setLeftVisibility(true);
        binding.headView.setRightTxt("保存");
        binding.headView.setRightTxtVisibility(true);
        binding.temp.setText(BLEDeviceConfig.getInstance().getTargetTemp());
        binding.headView.setOnRightClickListener(new HeadView.OnRightClickListener() {
            @Override
            public void onRightClickListener(View view) {
                try {
                    double temp = Double.parseDouble(binding.temp.getText().toString());
                    BLEDeviceConfig.getInstance().targetTemp = temp;
                    BLEDeviceConfig.writeConfig(SettingTempActivity.this);
                    finish();
                    EventBus.getDefault().post(SettingTempActivity.this.getClass().getName());
                }catch (Exception e) {

                }
            }
        });

    }
}